package com.easywork.mystery.controller;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.easycore.utils.BaseController;
import com.easywork.mystery.entity.MsgComm;
import com.easywork.mystery.entity.MsgInfo;
import com.easywork.mystery.service.MsgCommService;
import com.easywork.mystery.service.MsgInfoService;

@Controller
@RequestMapping("/mona/MsgInfo")
public class MsgInfoController extends BaseController {
	@Autowired
	private MsgInfoService msginfoService;
	@Autowired
	private MsgCommService msgcommService;

	// --根据id查看邮件内容
	@RequestMapping("/seeMail")
	public String seeMail(Long id, Model model) {
		MsgComm msgComm = msgcommService.findById(id);
		Long infoId = msgComm.getMsgId();
		MsgInfo msgInfo = msginfoService.findById(infoId);
		HashMap<String, Object> hashMap = new HashMap<>();
		hashMap.put("msgComm", msgComm);
		hashMap.put("msgInfo", msgInfo);
		model.addAttribute("map", hashMap);
		return "demo/mailtext";
	}

	// --根据id删除邮件
	@RequestMapping("/delMail")
	@ResponseBody
	public String delById(Long id) {
		MsgComm msgComm = msgcommService.findById(id);
		msgComm.setState(0);
		msgcommService.saveMsgComm(msgComm);
		return "success";
	}

	// -- 回复邮件
	@RequestMapping("/reply")
	public String replyMsg(Long id, Model model) {
		MsgComm msgComm = msgcommService.findById(id);
		String receiverAccount = msgComm.getReceiverAccount();
		String title = "回复:(" + msgComm.getMsgTitle() + ")";
		model.addAttribute("receiverAccount", receiverAccount);
		model.addAttribute("title", title);
		return "/demo/reply";
	}

	// -- 转发邮件
	@RequestMapping("/forward")
	public String forwarding(Long id, Model model) {
		MsgInfo msgInfo = msginfoService.findById(id);
		String content = msgInfo.getContent();
		String title = "转发邮件:(" + msgInfo.getTitle() + ")";
		model.addAttribute("content", content);
		model.addAttribute("title", title);
		return "/demo/forward";
	}

	// --路由跳转至收件箱
	@RequestMapping("/toReceive")
	public String toReceive() {
		return "/demo/receiver";
	}

}